package com.itheima.practice;

import java.util.*;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class StreamDemo {
    public static void main(String[] args) {
        //单列集合的获取流的对象方法
        method1();
        //双列集合间接的获取流的对象方法
        //System.out.println("--------------------");
        //method2();
        //数组的获取流的对象方法
        //System.out.println("--------------------");
        //method3();
        //同种数据获取流的对象方法,同stream.of()获取流的对象
    }

    private static void method3() {
        String[] arr ={"a","b","c","d","f","g"};
        Arrays.stream(arr).forEach(s-> System.out.println(s));
    }

    private static void method2() {
        HashMap<Integer,String> mp = new HashMap<>();
        mp.put(1,"张三");
        mp.put(2,"李四");
        mp.put(3,"王五");
        mp.put(4,"赵六");
        mp.put(5,"周七");
        //双列集合，只能间接的获取Stream流对象，通过keySet
        Set<Integer> key = mp.keySet();
        key.stream().forEach(s-> System.out.println(s));
        System.out.println("-------------------------");
        //通过enteykey
        Set<Map.Entry<Integer, String>> entrySet = mp.entrySet();
        entrySet.stream().forEach(s-> System.out.println(s));
    }

    private static void method1() {
        ArrayList<String> list = new ArrayList<>(List.of("aa","abb","ccac"));
        //使用filter中间方法对数据进行过滤
        List<String> list1 = list.stream().filter(new Predicate<String>() {
            @Override
            public boolean test(String s) {
                boolean a = s.startsWith("a");
                return a;
            }
        }).collect(Collectors.toList());
        for (String s : list1){
            System.out.println(s);
        }
    }
}
